package com.tiny_wind.resource_manager.service.impl;


import com.tiny_wind.resource_manager.dao.UserDao;
import com.tiny_wind.resource_manager.entity.TokenEntity;
import com.tiny_wind.resource_manager.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl  {

//	private Logger logger = LoggerFactory.getLogger(this.getClass());

	// 注入Service依赖
	@Autowired
	private UserDao mDao;


	/**
	 *
	 * @param account
	 * @param password
	 * @return
	 */
	public UserEntity login(String account, String password) {
		UserEntity entity = mDao.searchByAccount(account);
		return entity;
	}

	//注册不得生成账号,然后login返回一个Token
	public void register(UserEntity user) {
		String password_md5 = MD5 user.password;
		mDao.insert(user);
	}

	/**
	 * 通过用户名查找
	 * @param account
	 * @return
	 */
	public UserEntity searchByAccount(String account) {
		UserEntity entity = mDao.searchByAccount(account);
		return entity;
	}

	public UserEntity searchByUserId(Integer userId) {
		UserEntity entity = mDao.searchByUserId(userId);
		return entity;
	}
	
	public void insertToken(TokenEntity token) {
		mDao.insertToken(token);
	}
}
